a = {'zero': 0, 'one': 1, 'two': 2, 'three': 3, 'four': 4,
     'five': 5, 'six': 6, 'seven': 7, 'eight': 8, 'nine': 9}


def prime(x):
    if x == 1:
        return False
    for i in range(2, int(x ** 0.5) + 1):
        if x % i == 0:
            return False
    return True


b = input().split()
if len(b) != 3:
    print('Wrong input')
else:
    otv = []
    minn = 809
    razn = []
    c = ''
    for i in b:
        c += str(a[i])
    c = int(c)
    for i in range(100, 999):
        if prime(i) is True:
            if abs(c - i) < minn:
                minn = i
                otv.append(i)
                razn.append(abs(c - i))
    s = min(razn)
    ss = []
    for i in range(len(otv)):
        x = razn.index(s)
        if x == i:
            ss.append(otv[x])
    ss = min(ss)
    print(ss)
